﻿//
//
// 版权所有 (c) 2021-2023 JR  
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionRequest.Types;

namespace EMC.VISITOR.Core;
/// <summary>
/// 页面配置
/// </summary>
[SugarTable("SysPOConfig", "页面配置")]
[SysTable]
public class SysPageOptionConfig : EntityBase
{
    [SugarColumn(IsNullable = true, ColumnDescription = "路由路径")]
    public string configPath { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "配置名称")]
    public string configName { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "配置代码")]
    public string configCode { get; set; }

    /// <summary>
    /// 表格高度
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "表格高度")]
    public string height { get; set; } = "80%"; //"auto";
    [SugarColumn(IsNullable = true, ColumnDescription = "数据为空的提示")]
    public string emptyText { get; set; } = "暂无数据";
    /// <summary>
    /// 表格高度差（主要用于减去其他部分让表格高度自适应）
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "表格高度差")]
    public int calcHeight { get; set; } = 30;


    [SugarColumn(IsNullable = true, ColumnDescription = "表单栏间距")]
    public int gutter { get; set; } = 0;
    /// <summary>
    /// 首次加载是否显示搜索
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "首次加载是否显示搜索")]
    public bool? searchShow { get; set; } = false;
    /// <summary>
    /// 搜索框长度  最大长度24
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "搜索框长度")]
    public int searchSpan { get; set; } = 4;
    /// <summary>
    /// 搜索菜单栏的栅格宽度（整个搜索栏包括input框 按钮整个菜单栏的宽度）
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "搜索菜单栏的栅格宽度")]
    public int searchMenuSpan { get; set; } = 4;
    /// <summary>
    /// 查看按钮
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "查看按钮")]
    public bool? viewBtn { get; set; } = false;

    [SugarColumn(IsNullable = true, ColumnDescription = "列表行操作栏显示")]
    public bool? menu { get; set; } = true;

    [SugarColumn(IsNullable = true, ColumnDescription = "列表拖拽")]
    public bool? sortable { get; set; }
    ///// <summary>
    ///// 为：menu 合并操作栏按钮 ，空：不合并
    ///// </summary>
    //[SugarColumn(IsNullable = true, ColumnDescription = "合并操作栏按钮")]
    //public string menuType { get; set; } = "menu";
    ///// <summary>
    ///// 合并按钮显示名称
    ///// </summary>
    //[SugarColumn(IsNullable = true, ColumnDescription = "合并按钮显示名称")]
    //public string menuBtnTitle { get; set; } = "操作";


    //[SugarColumn(IsNullable = true, ColumnDescription = "列表行操作栏显示")]
    //public bool? menuBtn { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "列表行操作栏宽度")]
    public int? menuWidth { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "顶部过滤按钮")]
    public bool? filterBtn { get; set; } = true;
    /// <summary>
    /// 搜索收缩图标
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "搜索收缩图标")]
    public bool? searchIcon { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "打印按钮")]
    public bool? printBtn { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "导出按钮")]
    public bool? excelBtn { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "列表框框")]
    public bool? border { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "索引序号")]
    public bool? index { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "索引名称")]
    public string indexLabel { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "弹框宽度")]
    public string dialogWidth { get; set; } = "80%";



    #region 保存/配合新增行使用（true:显示保存、取消按钮）
    [SugarColumn(IsNullable = true, ColumnDescription = "保存按钮/取消按钮")]
    public bool? cellBtn { get; set; } = true;
    #endregion

    #region 新增-自定义按钮
    [SugarColumn(IsNullable = true, ColumnDescription = "新增按钮")]
    public bool? addCustomBtn { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "新增按钮描述")]
    public string addCustomText { get; set; } = "新增";
    [SugarColumn(IsNullable = true, ColumnDescription = "新增按钮图标")]
    public string addCustomIcon { get; set; } = "ele-Plus";
    #endregion

    #region 保存-自定义按钮
    [SugarColumn(IsNullable = true, ColumnDescription = "保存按钮")]
    public bool? saveCustomBtn { get; set; } = false;
    [SugarColumn(IsNullable = true, ColumnDescription = "保存按钮描述")]
    public string saveCustomText { get; set; } = "保存";
    [SugarColumn(IsNullable = true, ColumnDescription = "保存按钮图标")]
    public string saveCustomIcon { get; set; } = "ele-Edit";
    #endregion

    #region 编辑-自定义按钮
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑按钮")]
    public bool? editCustomBtn { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑按钮描述")]
    public string editCustomText { get; set; } = "编辑";
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑按钮图标")]
    public string editCustomIcon { get; set; } = "ele-Edit";
    #endregion

    #region 删除-自定义按钮
    [SugarColumn(IsNullable = true, ColumnDescription = "刪除按钮")]
    public bool? delCustomBtn { get; set; } = true;
    [SugarColumn(IsNullable = true, ColumnDescription = "刪除按钮描述")]
    public string delCustomText { get; set; } = "刪除";
    [SugarColumn(IsNullable = true, ColumnDescription = "刪除按钮图标")]
    public string delCustomIcon { get; set; } = "ele-Delete";
    #endregion


    [SugarColumn(IsNullable = true, ColumnDescription = "配置按钮")]
    public bool? settingBtn { get; set; } = true;

    [SugarColumn(IsNullable = true, ColumnDescription = "列表主键")]
    public string rowKey { get; set; } = "id";

    [SugarColumn(IsNullable = true, ColumnDescription = "勾选框")]
    public bool? selection { get; set; } = true;

    /// <summary>
    /// 勾选框禁用事件
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "勾选框禁用事件")]
    public string selectable { get; set; } = "(row,index)=>{ return true;}";

    [SugarColumn(IsNullable = true, ColumnDescription = "翻页勾选/保留之前的勾选")]
    public bool? reserveSelection { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "列表多选")]
    public bool? tableMultiple { get; set; } = true;

    [SugarColumn(IsNullable = true, ColumnDescription = "展开行")]
    public bool? expand { get; set; } 

    [SugarColumn(IsNullable = true, ColumnDescription = "展开树")]
    public bool? tree { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "最多展开层")]
    public int? expandLevel { get; set; } = 3;
    /// <summary>
    /// 表格弹窗是否可以通过点击modal关闭
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "表格弹窗是否可以通过点击modal关闭")]
    public bool? dialogClickModal { get; set; }

    /// <summary>
    /// 弹出框字段描述列宽
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "弹出框字段描述列宽")]
    public int? labelWidth { get; set; } = 100;
    [SugarColumn(IsNullable = true, ColumnDescription = "表头对其")]
    public string headerAlign { get; set; } = "center";
    [SugarColumn(IsNullable = true, ColumnDescription = "居中")]
    public string align { get; set; } = "center";

    [SugarColumn(IsJson = true, IsNullable = true, ColumnDescription = "排序")]
    public DefaultSort defaultSort { get; set; } = new DefaultSort();
    [SugarColumn(IsNullable = true, ColumnDescription = "弹出框拖拽")]
    public bool? dialogDrag { get; set; }
    /// <summary>
    /// 弹出框样式,默认从左右往左弹出
    /// ltr：从左往右开
    /// rtl：从右往左开
    /// ttb：从上往下开
    /// btt：从下往上开 
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "弹出框样式")]
    public string dialogDirection { get; set; } = "rtl";
    /// <summary>
    /// 弹出框样式类型,默认抽屉形式
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "弹出框样式类型")]
    public string dialogType { get; set; } = "drawer";

    /// <summary>
    /// 行拖拽
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "行拖拽")]
    public bool? rowSort { get; set; }


    /// <summary>
    /// 列
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(SysPageOptionConfigColumn.configPath), nameof(configPath))]
    public List<SysPageOptionConfigColumn> column { get; set; }

    #region MyRegion
    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override DateTime? CreateTime { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override DateTime? UpdateTime { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override long? CreateUserId { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override long? UpdateUserId { get; set; }

    [JsonIgnore]
    [SugarColumn(IsIgnore = true)]
    public override bool? cellEdit { get; set; }
    #endregion

    /// <summary>
    /// 展开行需要记录的Key值
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public List<int> expandRowKeys { get; set; } = new List<int>();

    /// <summary>
    /// 初始化
    /// </summary>
    public void Init()
    {
        this.height = "auto";
        this.emptyText = "暂无数据";
        this.calcHeight = 30;
        this.gutter = 0;

        this.searchShow = false;
        this.searchSpan = 4;
        this.searchMenuSpan = 4;

        this.dialogWidth = "80%";
        this.dialogDrag = true;

        this.selection = true;
        this.tableMultiple = true;
        this.menu = true;
        this.border = true;
        this.index = true;

        this.filterBtn = true;
        this.searchIcon = true;
        this.printBtn = true;
        this.excelBtn = true;
        this.cellBtn = false;
        this.viewBtn = false;

        this.addCustomBtn = true;
        this.addCustomText = "新增";
        this.addCustomIcon = "ele-Plus";

        this.editCustomBtn = true;
        this.editCustomText = "编辑";
        this.editCustomIcon = "ele-Edit";

        this.delCustomBtn = true;
        this.delCustomText = "删除";
        this.delCustomIcon = "ele-Delete";

        this.saveCustomBtn = false;
        this.saveCustomText = "保存";
        this.saveCustomIcon = "ele-Edit";

        this.defaultSort = null;
        this.indexLabel = "id";
        this.rowKey = "id";
        this.labelWidth = 100;
        this.headerAlign = "center";
        this.align = "center";


    }

    public override async Task DoSomeThingSaveChildren(ISqlSugarClient _db = null)
    {
        if (this.column != null && this.column.Count() > 0)
        {
            await _db.MyUpdateable<SysPageOptionConfigColumn>(this.column).ExecuteCommandAsync();
        }
    }
}

public class SysPageOptionConfigView : SysPageOptionConfig
{
    #region 新增-系统新增
    [SugarColumn(IsNullable = true, ColumnDescription = "新增按钮")]
    public bool? addBtn { get; set; } = false;
    #endregion

    #region 新增行/不弹窗直接新增行/配合保存按钮使用/跟addBtn共用描述、图表
    [SugarColumn(IsNullable = true, ColumnDescription = "新增行")]
    public bool? addRowBtn { get; set; } = false;
    #endregion

    #region 编辑
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑按钮")]
    public bool? editBtn { get; set; } = false;
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑按钮描述")]
    public string editBtnText { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "编辑按钮图标")]
    public string editBtnIcon { get; set; }
    #endregion

    #region 删除
    [SugarColumn(IsNullable = true, ColumnDescription = "刪除按钮")]
    public bool? delBtn { get; set; } = false;
    [SugarColumn(IsNullable = true, ColumnDescription = "刪除按钮描述")]
    public string delBtnText { get; set; }
    [SugarColumn(IsNullable = true, ColumnDescription = "刪除按钮图标")]
    public string delBtnIcon { get; set; }
    #endregion

}


public class DefaultSort
{
    public string prop { get; set; } = "name";
    public string order { get; set; } = "descending";
}

